package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.PageResult;
import cn.wolfcode.mapper.EmpMapper;
import cn.wolfcode.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public PageResult query(int page, int pageSize, String name, Integer gender, Date begin, Date end) {

//        // 查询 数据
//        int start = (page-1)*pageSize;
//       List<Emp> emps= empMapper.query(page,pageSize);
//       //查询 条数
//       long count= empMapper.selForCount();
        // 给插件设置分页参数
        PageHelper.startPage(page, pageSize);
        // 正常执行查询
        List<Emp> emps = empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) emps;
        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }
}
